#pragma once

#include "Config.h"

#ifdef _DB_USE_ZLIB

#include "DBStream.h"
#include <deque>

namespace db
{

struct MemoryBlock;

class WriteCompressedStream : public WriteStream
{
private:
    static const int DATA_CHUNK_SIZE = 65535;

    WriteStream&       m_outStream;
    std::deque<MemoryBlock*>  m_buffers;

    MemoryBlock* allocBlock(size_t sizeOf = DATA_CHUNK_SIZE);
    MemoryBlock* topBlock();
public:

    WriteCompressedStream(WriteStream& outStream);
	bool write(const void* data, const unsigned int size);
    void complete();
    void prepare();
};

class ReadCompressedStream : public ReadStream
{
private:
    ReadStream&       m_inStream;
    char*             m_buffer;
    unsigned long     m_bufferSize, m_bufferPos;
public:

    ReadCompressedStream(ReadStream& inStream);
	bool read(void* data, const unsigned int size);
    void complete();
};

};

#endif